import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    token: "",
    username: ""
  },
  actions: {},
  mutations: {
    setToken(state, payload) {
      state.token = payload;
    },

    setUsername(state, payload) {
      state.username = payload;
      window.localStorage.setItem("username", payload);
    }
  },
  getters: {
    getUsername(state) {
      if (state.username) {
        return state.username;
      }
      return window.localStorage.getItem("username");
    }
  }
});
export default store;
